Repository navigation
fix(codegen-kotlin): write Spring controller through KotlinWriter - #660
Merged
Merged
Conversation
…otlinWriter (W-KT-3) KotlinSpringControllerGenerator (the writable, TPH base and read-only controllers, with the filter pipeline, M:N traversal routes, sort surface and credential redactor they share) now writes through KotlinWriter (ADR-0063) instead of hand-indented StringBuilder text. Its entry leaves the Kotlin layout ratchet's allowlist. Generated output changes in layout only: imports in one sorted group, no blank line at the start or end of the controller class, and two bodies the old builder indented one level off (the Exposed 1.x WhereOp loop, and a PATCH handler whose only automatic column is @autoset) now indented by their blocks. The six controller snapshot goldens are refreshed. The protected open hooks (emitFilterPipeline, emitPerFieldDispatchArm, emitTypedCoercer, emitM2mEndpoint, emitTphSubtypeM2mEndpoint) take a KotlinWriter where they took a StringBuilder; an owned copy ejected at an earlier version carries its own and still compiles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
KotlinSpringControllerGeneratornow writes the writable, TPH base, and read-only (projection and report) controllers throughKotlinWriterinstead of a hand-typedStringBuilderlayout.sortColumnExprbecamewriteOrderBy, which writes the sameorderBywhen-expression through the writer. Its entry leaves the layout-ratchet allowlist.WhereOploop and a PATCH handler whose only automatic column is@autoSet) are indented by their blocks. Compiled behaviour is unchanged.opensubclasses:emitFilterPipeline,emitPerFieldDispatchArm,emitTypedCoercer,emitM2mEndpointandemitTphSubtypeM2mEndpointtake aKotlinWriterwhere they took aStringBuilder. Owned copies ejected at an earlier version keep their own code and still compile (EjectedAtBaseGeneratorsCompatTest). Recorded in CHANGELOG 1.3.0.Author evidence (local, before the gate)
meta*.jsoninfixtures/and the codegen-kotlin test resources (515 models) x 3 arg variants (exposedApi 0 defaults; exposedApi 1 + pagination + reject-unknown + report export; exposedApi 0 + pagination + allow + report export) = 3,774 generated files. Ignoring indentation, blank lines and import order: 0 text differences. Indentation differs only in the two bodies named above.codegen-kotlinmodule: 706 tests, 0 failures (layout ratchet, six refreshed controller goldens, codegen compile gate, ejected-at-base compat).scripts/ci-local.sh --only javapassed: conformance java + kotlin, java-reactor (incl. the Exposed 1.x controller compile check), integration-tests java, and integration-tests kotlin (the generated api-contract lanes against Testcontainers Postgres).passed-with-override). One no-mistakes run.Validation
Risk Assessment
✅ Low: The change is a mechanical move from StringBuilder to KotlinWriter: the golden diffs are layout only (import order, blank lines), the only multi-line snippet (stripCredentials) matches the old trimMargin text, writeOrderBy writes the same when-expression, and the writer fails loudly on embedded newlines, unbalanced blocks and import conflicts, so the remaining risk is only the intended change to the protected hook signatures, which the CHANGELOG records.
Testing
Baseline affected-lane command passed. I re-ran the focused Kotlin suites for the ratchet, controller generator, eject-at-base compat, compile gates and snapshots against the worktree; all pass with fresh surefire reports. I did not drive the generator live through the Maven plugin or the CLI on a fixture, so no scenario is live and none is marked pass. Verdict inconclusive: the layout-only change is supported by the focused tests and the author's equivalence harness, but live product validation was not performed.
mvn metaobjects:generateon a fixture needs the reactor plugin install, which is outside this step's time bu…Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
CHANGELOG.md:1659- The CHANGELOG called its list of layout diffs complete ("Regenerating shows those diffs and nothing else"), but the refreshed TPH golden (entity-with-tph/acme/auth/AuthController.kt, old line 677) also collapses a doubled blank line before the exception handlers. I added "one blank line where the TPH controller wrote two (before its exception handlers)" to the list. This is a documentation edit only; the layout-only requirement still holds.server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinSpringControllerGenerator.kt:2827- The KDoc on writeOrderBy (formerly sortColumnExpr) still said "The generated Kotlin expression resolving a sort FIELD NAME…". It now writes the wholeq = q.orderBy(...)statement through the writer, so I reworded the first line to "Writes theq = q.orderBy(...)statement whosewhenresolves a sort FIELD NAME to its Exposed column." Comment edit only.mvn metaobjects:generateon a fixture needs the reactor plugin install, which is outside this step's time bu…scripts/ci-local.sh --affected --strict-toolchainsmvn -o -q -pl codegen-kotlin -am test -Dtest='KotlinLayoutRatchetTest,KotlinSpringControllerGeneratorTest*,EjectedAtBaseGeneratorsCompatTest'in server/java (exit 0; surefire: ratchet 20/20, controller 8/8, eject-at-base 3/3, 0 failures)mvn -o -q -pl codegen-kotlin -am test -Dtest='CodegenCompileConformanceTest,KotlinWriteThroughCompileTest,KotlinCodegenSnapshotTest,KotlinCodegenE2ETest,KotlinM2mTraversalCompileRunTest'(exit 0; 2, 4, 18, 1, 1 tests, 0 failures)Readserver/java/codegen-kotlin/src/test/resources/layout-ratchet/allowlist.json: controller entry removed, no other changeBaseline:scripts/ci-local.sh --affected --strict-toolchainspassed at target commit (broad regression, not re-run)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.